package com.naml.d_methods;

/**
 * @author marin
 * @version 1.0
 * @date 2025/5/2 15:18
 * @desc 演示演示的生命周期（部分）
 */
@SuppressWarnings("all")
public class ThreadLife05 {
    public static void main(String[] args) throws InterruptedException {
        ThreadLife threadLife = new ThreadLife();
        //启动前线程的状态
        System.err.println("启动前线程的状态>>>"+threadLife.getState());
        threadLife.start();

        while(!(threadLife.getState() == Thread.State.TERMINATED)){
            Thread.sleep(3000);
            System.out.println("线程启动后的状态>>>"+threadLife.getState());
        }

        System.err.println("线程运行结束后的状态>>>"+threadLife.getState());
    }
}

class ThreadLife extends Thread {

    @Override
    public void run() {
        for (int i = 0; i < 30; i++) {
            try {
                Thread.sleep(1000);
                System.out.println("跑了>>>"+i +"米...");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

